//
//  EFFeatureCell.m
//  EnjogFood
//
//  Created by 王芳 on 17/5/6.
//  Copyright © 2017年 wf. All rights reserved.
//

#import "EFFeatureCell.h"
#import "EFFearchItem.h"
#import "EFFeatureHeadView.h"
#import "EFSepecialItem.h"
#import "EFBigSaleView.h"

static const CGFloat saleWidth = 165;
static const CGFloat saleHeight = 240;
@interface EFFeatureCell ()

@end

@implementation EFFeatureCell

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = RGBCOLOR(0xf5f9f9);
    }
    return self;
}

- (void)setObject:(EFFearchItem *)featureItem{
     CGFloat marginX = (kScreenWidth - 2*saleWidth - 5)/2 ;
    EFFeatureHeadView *headView = [[EFFeatureHeadView alloc] initWithFrame:CGRectMake(marginX, 20, saleWidth, saleHeight)];
    [headView refreshUI:featureItem];
    [self.contentView addSubview:headView];
   
    CGFloat x = 0;
    CGFloat y = 20;
    for (int i = 0; i < featureItem.productList.count; i++) {
        if (i == 0) {
            //放到第一行的第二个
            EFBigSaleView *firstView = [[EFBigSaleView alloc] initWithFrame:CGRectMake(headView.right + 5, 20, saleWidth, saleHeight)];
            [firstView refreshUI:featureItem.productList[i]];
            [self.contentView addSubview:firstView];
        }else{
            if (i%2 == 0) {
                x = marginX;
            }else if(i%2 == 1){
                x = marginX + saleWidth + 5;
            }
            y = (i - 1)/2 *(saleHeight + 5) + headView.bottom + 5;
            EFBigSaleView *view = [[EFBigSaleView alloc] initWithFrame:CGRectMake(x, y, saleWidth, saleHeight)];
            [view refreshUI:featureItem.productList[i]];
            [self.contentView addSubview:view];
        }
    }
}

+ (CGFloat)cellHeight:(EFFearchItem *)featureItem{
    CGFloat height = 20 + (featureItem.productList.count + 1)/2 * 240 + ((featureItem.productList.count + 1)/2 - 1)*5;
    return height;
}


@end
